package fileIO;
//点一下跑，点一下停
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class PmdFrame extends JFrame {
	private JTextField text = new JTextField(20);
	private JButton btn = new JButton("go");
	private boolean running = false;
	private boolean stop=true;
	
	public PmdFrame(){
		setLayout(new FlowLayout());
		add(text);
		add(btn);
		
		btn.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				if(!running){
					btnClicked();
				}else{
					stop = !stop;
					running=!running;
				}
				
			}

			private void btnClicked() {
				stop = !stop;
				new Thread(){
					@Override
					public void run() {
						String s = text.getText();
						int len = s.length();
						char[] ch = s.toCharArray();
						int i=1;
						for(;!stop;){
							StringBuilder sb = new StringBuilder(ch.length);
							for (int j = 0; j < ch.length; j++) {
								sb.append(ch[i++%len]);
							}
							i++;
							System.out.println(sb.toString());
							text.setText(sb.toString());
							try {
								Thread.sleep(1000);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						}
					}
				}.start();
			}
			
		});
		
//		btn.addMouseListener(new MouseAdapter(){
//			@Override
//			public void mouseClicked(MouseEvent e) {
//				btnclicked();
//			}
//
//			private void btnclicked() {
//				while(true){
//					String s = text.getText();
//					String s1 = s.substring(0,s.length()-1);
//					String s2 = s.substring(s.length()-1);
//		s=s2+s1;
//					text.setText(s);
//					try {
//						Thread.sleep(1000);
//					} catch (InterruptedException e) {
//						// TODO Auto-generated catch block
//						e.printStackTrace();
//					}
//				}
//				
//			}
//
//		});
		
		
		setSize(300,200);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	}
	public static void main(String[] args) {
		PmdFrame f = new PmdFrame();
		f.setVisible(true);
	}
	
}
